package com.kcl.dfss;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MatchingWiFiActivity extends Activity implements OnClickListener{

	private static final String TAG = "MatchingWiFiActivity";
	private LinearLayout select_model_back;
	private TextView text_skip,text_wifi;
	private Button btn_wifinext;
	
	private boolean cameraisconnect = false;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_matching_wifi);
		
		select_model_back = (LinearLayout) findViewById(R.id.select_model_back);
		text_skip = (TextView) findViewById(R.id.text_skip);
		text_wifi = (TextView) findViewById(R.id.text_wifi);
		btn_wifinext = (Button) findViewById(R.id.btn_wifinext);
		
		select_model_back.setOnClickListener(this);
		text_skip.setOnClickListener(this);
		text_wifi.setOnClickListener(this);
		btn_wifinext.setOnClickListener(this);
		btn_wifinext.setEnabled(false);
		
		startLocationService();

	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.select_model_back:
			finish();
			break;
		case R.id.text_skip:
			startActivity(new Intent(MatchingWiFiActivity.this, MatchingCarActivity.class));
			break;
		case R.id.text_wifi:
			startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
			break;
		case R.id.btn_wifinext:
			startActivity(new Intent(MatchingWiFiActivity.this, MatchingCarActivity.class));
			break;
		}
	}
	
	private void startLocationService() {
		Intent intent = new Intent(this, LocationService.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startService(intent);
		Log.i(TAG, "Service on start");
	}

	@Override
	protected void onResume() {
		super.onResume();
		Log.i(TAG, "onResume");
		cameraisconnect = LocationService.getCamemraConnected();
		Log.i(TAG, "onResume: "+cameraisconnect);
		if(cameraisconnect){
			btn_wifinext.setBackgroundResource(R.drawable.changepwd_selector);
			btn_wifinext.setEnabled(true);
		}else{
			btn_wifinext.setBackgroundResource(R.drawable.changepwd_noclick);
			btn_wifinext.setEnabled(false);
		}
	}

	@Override
	protected void onPause() {
		super.onPause();
		Log.i(TAG, "onPause");
	}

	@Override
	protected void onStop() {
		super.onStop();
		Log.i(TAG, "onStop");
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		
	}
	
}
